import pickle
from selenium import webdriver


def save_cookies():
    # 设置浏览器选项
    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable-automation'])
    options.add_argument("disable-blink-features=AutomationControlled")
    options.add_argument(
        'User-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36')

    # 初始化浏览器
    driver = webdriver.Chrome(options=options)

    # 打开网站
    driver.get("https://www.kongfz.com")

    # 在这里手动登录网站
    input("请手动登录网站后按Enter继续...")

    # 保存Cookie
    cookies = driver.get_cookies()
    with open('../cookies.pkl', 'wb') as f:
        pickle.dump(cookies, f)

    driver.quit()


save_cookies()